home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_214 / memdiag / addaddr.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  53 lines

  1. void
  2. AddAddr(address)
  3. unsigned char *address;
  4. {
  5.    extern unsigned char *Addr[];
  6.    extern short int AddrCnt;
  7.    int i;
  8.  
  9.    /* If it's the first address we just add it. */
  10.    if (AddrCnt == 0)
  11.       Addr[AddrCnt++] = address;
  12.    else
  13.    {
  14.       /* If there are already 100 addresses we can't process any more so
  15.          we'll just return. */
  16.       if (AddrCnt == 100)
  17.          return;
  18.  
  19.       /* We'll compare the new address against each one in the list until we
  20.          find the appropriate place to insert it. */
  21.       for (i = 0; i < AddrCnt; i++)
  22.       {
  23.          /* If the new address is smaller than the current address in the
  24.             array we'll insert the new one at this position. */
  25.          if (address < Addr[i])
  26.          {
  27.             /* We need a temporary loop counter so we can move all the array
  28.                entries from the current one to the end down one position to
  29.                make room for the new address. */
  30.             int j;
  31.  
  32.             for (j = AddrCnt; j > i; j--)
  33.                Addr[j] = Addr[j-1];
  34.             Addr[i] = address;
  35.             AddrCnt++;
  36.             break;
  37.          }
  38.  
  39.          /* If the address is already in the list we'll skip it. */
  40.          if (address == Addr[i])
  41.             break;
  42.       }
  43.  
  44.       /* If the new address is higher than the last one on the list we'll
  45.          add it to the end of the array. */
  46.       if (address > Addr[AddrCnt-1])
  47.          Addr[AddrCnt++] = address;
  48.  
  49.       return;
  50.    }
  51. }
  52.  
  53.